module Lark
  module Apis
    module Approval
      #  查看审批定义
      def get(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/approval/get', payload
      end

      # 批量获取审批实例ID
      def list(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/instance/list', payload
      end

      # 获取单个审批实例详情
      def get_details(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/instance/get', payload
      end

      #  创建审批实例
      def create_approved(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/instance/create', payload
      end

      #  审批任务同意
      def approve(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/instance/approve', payload
      end

      #  审批任务拒绝
      def reject(payload={} )
        post 'https://www.feishu.cn/approval/openapi/v2/instance/reject', payload
          
      end

      #  审批任务转交
      def transfer(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/instance/transfer', payload
      end

      #  审批任务撤回
      def cancel(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/instance/cancel', payload
      end

      # 上传文件
      def upload(name:, type: 'attachment', content:)
        post 'https://www.feishu.cn/approval/openapi/v2/file/upload', {
          name: name,
          type: type,
          content: content
        }, { 'Content-Type': 'multipart/form-data' }
      end

      def upload_file(name: ,type: 'attachment', file:)
        post_form 'https://www.feishu.cn/approval/openapi/v2/file/upload', {
          name: name,
          type: type,
          content: file
        }
      end

      # 订阅审批事件
      def subscribe(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/subscription/subscribe', payload
      end

      # 取消订阅审批事件
      def  unsubscribe(payload={})
        post 'https://www.feishu.cn/approval/openapi/v2/subscription/unsubscribe', payload
      end

    end
  end
end